/******************************************************************************
 * FileName:    gwin_main_task.h
 * Desc:        main
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef __GWIN_MAIN_H__
#define __GWIN_MAIN_H__


/*-------------------------- Includes ---------------------------------------*/
#include "gwin_global_data.h"
#include "gwin_global_config.h"


/*-------------------------- Macro Definitions ------------------------------*/

/*-------------------------- Type Declarations ------------------------------*/
/**
 * @brief 消息
 */
typedef struct
{
    uint16_t type;
    uint16_t subtype;
    union
    {
        uint32_t param;
        void *buf;
        // 设置参数
        struct
        {
            uint8_t action_type;
            uint8_t reserve1;
            uint16_t reserve2;
            uint32_t cfg_value;
        };
        // 外部动作
        struct
        {
            uint32_t ext_param;
            uint8_t from_remote;
        };
    };
}gwin_main_task_msg_t;


/**
 * @brief 消息类型
 */
typedef enum
{
    MAIN_TASK_MSG_TYPE_NONE,
    MAIN_TASK_MSG_TYPE_TASK_INIT,
    MAIN_TASK_MSG_TYPE_TIMER,
    MAIN_TASK_MSG_TYPE_CFG,
    MAIN_TASK_MSG_TYPE_EX_ACT,
}gwin_main_task_msg_type_t;

/**
 * @brief 定时器消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_TIMER_SUBTYPE_NONE,
    MAIN_TASK_MSG_TIMER_SUBTYPE_RESET_ALL_FORCE,
    MAIN_TASK_MSG_TIMER_SUBTYPE_PWR_ON_WAIT_LOOP,
    MAIN_TASK_MSG_TIMER_SUBTYPE_LOW_PWR_ENTER,
    MAIN_TASK_MSG_TIMER_SUBTYPE_ONE_SECOND,
    MAIN_TASK_MSG_TIMER_SUBTYPE_STOP_INFO_PKT,
}gwin_main_task_msg_timer_subtype_t;

/**
 * @brief 设置动作类型
 */
typedef enum
{
    MAIN_TASK_MSG_CFG_ACT_TYPE_NONE,
    MAIN_TASK_MSG_CFG_ACT_TYPE_SET,
    MAIN_TASK_MSG_CFG_ACT_TYPE_GET,
    MAIN_TASK_MSG_CFG_ACT_TYPE_TOGGLE,
    MAIN_TASK_MSG_CFG_ACT_TYPE_RESET,
}gwin_main_task_msg_cfg_action_type_t;

/**
 * @brief 设置消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_CFG_SUBTYPE_NONE,
    MAIN_TASK_MSG_CFG_SUBTYPE_TIME_ZONE,
    MAIN_TASK_MSG_CFG_SUBTYPE_UTC_TIME,
    MAIN_TASK_MSG_CFG_SUBTYPE_WEATHER,
    MAIN_TASK_MSG_CFG_SUBTYPE_SYS_STATE,
    MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK,
    MAIN_TASK_MSG_CFG_SUBTYPE_GATT,
    MAIN_TASK_MSG_CFG_SUBTYPE_OTA_STATE,
    MAIN_TASK_MSG_CFG_SUBTYPE_MAC_ADDR,
    MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK_TIMEOUT,
    MAIN_TASK_MSG_CFG_SUBTYPE_MODEL_PID,
    MAIN_TASK_MSG_CFG_SUBTYPE_SPEC_SECURITY,
    MAIN_TASK_MSG_CFG_SUBTYPE_SPEC,
    MAIN_TASK_MSG_CFG_SUBTYPE_SPEC_SAVE,
    MAIN_TASK_MSG_CFG_SUBTYPE_SET_INFO_PKT,
}gwin_main_task_msg_cfg_subtype_t;

/**
 * @brief 外部动作消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_NONE,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_WAKEUP,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_FUNC_START,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_LOW_PWR,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_ACTIVE_PAIR,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_NET_RESET,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_FACTORY_TEST,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_RESET_ALL_FORCE,       // 强制复位所有参数（研发预留接口，防止错误，直接响应）
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_SET_PAIR_MODE,         // 设置配对模式
}gwin_main_task_msg_ex_act_subtype_t;


/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
void gwin_main_task_init(void);
uint8_t gwin_send_msg_to_main_task(gwin_main_task_msg_t *p_msg);

void gwin_main_cfg_set(uint32_t cfg_index, uint32_t value);
void gwin_main_cfg_get(uint32_t cfg_index, uint32_t value_addr);
void gwin_main_extern_action(uint8_t action);
void gwin_main_extern_action_with_param(uint8_t action, uint32_t param);

void gwin_main_set_adv_dev_pair_info_pkt(const uint8_t *qrcode, uint8_t len);

void gwin_main_ble_set_adv_interval(uint8_t normal, uint8_t force);

void gwin_main_ble_set_cfg_info_pkt(void);

#endif // __GWIN_MAIN_H__


/*-------------------------- END OF FILE ------------------------------------*/

